package com.bbx.taxi.client.Util;

public class FormatUtil {
	/**
	 * 格式化电话号码，如：150****8265
	 */
	public static String onFormatTelephone(String telephone) {
		// if(telephone==null||telephone.length()<11){
		// return "";
		// }
		telephone = telephone.replace("+86", "");
		String tel;
		StringBuffer sb = new StringBuffer(telephone);
		// 暂时不掩码
		// tel = sb.substring(0, 3) + "****" + sb.substring(7, sb.length());
		tel = sb.toString();
		return tel;

	}

	/**
	 * 格式化分钟为小时
	 */
	public static String onFormatTime(String time_str) {
		double time = 0;
		try {
			time = Double.parseDouble(time_str);
		} catch (Exception e) {
		}
		if (time <= 0)
			return "0";
		return ((int) time / 60) + "";

	}

	/**
	 * 格式化公里
	 */
	public static String onFormatDistance(String distance_str) {
		double distance = 0;
		try {
			distance = Double.parseDouble(distance_str);
		} catch (Exception e) {
		}
		if (distance <= 0)
			return "0.0";
		distance = (double) distance / 1000;
		java.text.DecimalFormat df = new java.text.DecimalFormat("0.0");
		return df.format(distance);

	}

	/**
	 * 格式化价钱,分转化为元
	 */
	public static String onFormatPrice(int price) {
		if (price <= 0)
			return "0";
		double mprice = (double) price / 100;
		java.text.DecimalFormat df = new java.text.DecimalFormat("0");
		return df.format(mprice);

	}

	/**
	 * 格式化价钱,分转化为元
	 */
	public static String onFormatPrice(double price) {
		if (price <= 0)
			return "0";
		double mprice = (price / 100);
		java.text.DecimalFormat df = new java.text.DecimalFormat("0");
		return df.format(mprice);

	}

	/**
	 * 格式化价钱,分转化为元
	 */
	public static String onFormatPrice(String price_str) {
		long price = 0;
		try {
			price = Long.parseLong(price_str);
		} catch (Exception e) {
			try {
				price = (int)Double.parseDouble(price_str);
			} catch (Exception e1) {
			}
		}
		if (price <= 0)
			return "0";
		double mprice = (double) price / 100;
		java.text.DecimalFormat df = new java.text.DecimalFormat("0");
		return df.format(mprice);

	}

	/**
	 * 格式化价钱,分转化为元
	 */
	public static String onFormatPrice2(String price_str) {
		long price = 0;
		try {
			price =  Long.parseLong(price_str);
		} catch (Exception e) {
			try {
				price = (int)Double.parseDouble(price_str);
			} catch (Exception e1) {
			}
		}
		if (price <= 0)
			return "0";
		double mprice = (double) price / 100;
		java.text.DecimalFormat df = new java.text.DecimalFormat("0");
		return df.format(mprice);

	}
	/**
	 * 格式化价钱,分转化为元
	 */
	public static String onFormatPrice3(String price_str) {
		long price = 0;
		try {
			price =  Long.parseLong(price_str);
		} catch (Exception e) {
			try {
				price = (int)Double.parseDouble(price_str);
			} catch (Exception e1) {
			}
		}
		if (price <= 0)
			return "0";
		double mprice = (double) price / 100;
		java.text.DecimalFormat df = new java.text.DecimalFormat("0.0");
		return df.format(mprice);

	}

	/**
	 * 格式化价钱,0格式
	 */
	public static String onFormatDecimal(double price) {
		java.text.DecimalFormat df = new java.text.DecimalFormat("0");
		return df.format(price);

	}

	/**
	 * 格式化价钱,0.0格式
	 */
	public static String onFormatDecimal2(double price) {
		java.text.DecimalFormat df = new java.text.DecimalFormat("0.0");
		return df.format(price);

	}

	public static float onFormatStar(float star) {
		if (star == 0.0)
			return 0;
		float mstar = star / (100 / 5);
		java.text.DecimalFormat df = new java.text.DecimalFormat("0.0");
		return Float.parseFloat(df.format(mstar));
	}

	public static float onFormatStar(double star) {
		if (star == 0.0)
			return 0;
		double mstar = star / (100 / 5);
		java.text.DecimalFormat df = new java.text.DecimalFormat("0.0");
		return Float.parseFloat(df.format(mstar));
	}
}
